/**
*      author: Y_Yao
*      created: 2024-11-26 19:09:50
**/

#include<bits/stdc++.h>

using namespace std;
using LL = long long;
const LL LLINF = 1e18;
const int INF = 0x3f3f3f3f;
const int N = 100 + 7;
int a[N][N];
int r,c;

struct cmp
{
    bool operator()(pair<int,int>& x,pair<int,int>& y)
    {
        return a[x.first][x.second] > a[y.first][y.second];
    }
};

void solve()
{
    cin >> r >> c;
    vector<vector<int>> dp(N,vector<int>(N,0));
    priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> q;
    for(int i = 1;i <= r;i++)
    {
        for(int j = 1;j <= c;j++)
        {
            dp[i][j] = 1;
            cin >> a[i][j];
            q.push({i,j});
        }
    }

    int ans = 0;
    while(!q.empty())
    {
        auto t = q.top();
        q.pop();
        int i = t.first,j = t.second;
        if(a[i - 1][j] < a[i][j])
        {
            dp[i][j] = max(dp[i][j],dp[i-1][j] + 1);
        }
        if(a[i + 1][j] < a[i][j])
        {
            dp[i][j] = max(dp[i][j],dp[i+1][j] + 1);
        }
        if(a[i][j - 1] < a[i][j])
        {
            dp[i][j] = max(dp[i][j],dp[i][j - 1] + 1);
        }
        if(a[i][j + 1] < a[i][j])
        {
            dp[i][j] = max(dp[i][j],dp[i][j + 1] + 1);
        }

        if(ans < dp[i][j])
        {
            ans = dp[i][j];
        }
    }

    if(ans == 0) ans = 1;
    cout << ans << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
    return 0;
}